﻿// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com

// ReSharper disable CheckNamespace
// ReSharper disable CommentTypo
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo
// ReSharper disable UnusedMember.Global
// ReSharper disable UseNameofExpression

/* Extensions.Verbs.cs --
 * Ars Magna project, http://arsmagna.ru
 */

#region Using directives

using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

#endregion

#nullable enable

namespace AM.Web;

public static partial class ExtensionsForHttp
{
    /// <summary>
    /// Issue the request as a DELETE.
    /// </summary>
    /// <typeparam name="T">The return type.</typeparam>
    /// <param name="builder">The builder used for this request.</param>
    /// <param name="cancellationToken">The cancellation token for stopping the request.</param>
    /// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
    public static Task<HttpCallResponse<T>> DeleteAsync<T> (this IRequestBuilder<T> builder,
        CancellationToken cancellationToken = default) =>
        Http.SendAsync (builder, HttpMethod.Delete, cancellationToken);

    /// <summary>
    /// Issue the request as a GET.
    /// </summary>
    /// <typeparam name="T">The return type.</typeparam>
    /// <param name="builder">The builder used for this request.</param>
    /// <param name="cancellationToken">The cancellation token for stopping the request.</param>
    /// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
    public static Task<HttpCallResponse<T>> GetAsync<T> (this IRequestBuilder<T> builder,
        CancellationToken cancellationToken = default) =>
        Http.SendAsync (builder, HttpMethod.Get, cancellationToken);

    /// <summary>
    /// Issue the request as a HEAD.
    /// </summary>
    /// <typeparam name="T">The return type.</typeparam>
    /// <param name="builder">The builder used for this request.</param>
    /// <param name="cancellationToken">The cancellation token for stopping the request.</param>
    /// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
    public static Task<HttpCallResponse<T>> HeadAsync<T> (this IRequestBuilder<T> builder,
        CancellationToken cancellationToken = default) =>
        Http.SendAsync (builder, HttpMethod.Head, cancellationToken);

    /// <summary>
    /// Issue the request as a POST.
    /// </summary>
    /// <typeparam name="T">The return type.</typeparam>
    /// <param name="builder">The builder used for this request.</param>
    /// <param name="cancellationToken">The cancellation token for stopping the request.</param>
    /// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
    public static Task<HttpCallResponse<T>> PostAsync<T> (this IRequestBuilder<T> builder,
        CancellationToken cancellationToken = default) =>
        Http.SendAsync (builder, HttpMethod.Post, cancellationToken);

    /// <summary>
    /// Issue the request as a PUT.
    /// </summary>
    /// <typeparam name="T">The return type.</typeparam>
    /// <param name="builder">The builder used for this request.</param>
    /// <param name="cancellationToken">The cancellation token for stopping the request.</param>
    /// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
    public static Task<HttpCallResponse<T>> PutAsync<T> (this IRequestBuilder<T> builder,
        CancellationToken cancellationToken = default) =>
        Http.SendAsync (builder, HttpMethod.Put, cancellationToken);

    /// <summary>
    /// Issue the request as a PATCH.
    /// </summary>
    /// <typeparam name="T">The return type.</typeparam>
    /// <param name="builder">The builder used for this request.</param>
    /// <param name="cancellationToken">The cancellation token for stopping the request.</param>
    /// <returns>A <see cref="HttpCallResponse{T}"/> to consume.</returns>
    public static Task<HttpCallResponse<T>> PatchAsync<T> (this IRequestBuilder<T> builder,
        CancellationToken cancellationToken = default) =>
        Http.SendAsync (builder, new HttpMethod ("PATCH"), cancellationToken);
}
